package com.example.demo.mapper;

import com.example.demo.model.Book;
import com.example.demo.model.PageRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface BookMapper {
    /**
     * 增加图书
     */
    @Insert("insert into book_info (book_name, author, count, price, publish, status) " +
            "values (#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    Integer insertBook(Book book);

    /**
     * 获取图书列表
     */
    @Select("select id, book_name, author, count, price, publish, " +
            "status, create_time, update_time from book_info")
    List<Book> selectAllBooks();

    /**
     * 按页获取图书列表
     */
    @Select("select id, book_name, author, count, price, publish, " +
            "status, create_time, update_time from book_info " +
            "where status != 0 order by id asc " +
            "limit #{offset}, #{limit}")
    List<Book> selectBookByPage(PageRequest pageRequest);

    /**
     * 获取图书列表行数
     */
    @Select("select count(1) from book_info where status != 0")
    Integer selectBookTotalCount();

    /**
     *通过 id 获取图书
     */
    @Select("select id, book_name, author, count, price, publish, " +
            "status, create_time, update_time from book_info " +
            "where id = #{id}")
    Book selectBookById(Integer id);

    Integer updateBookById(Book book);

    @Update("update book_info set status = 0 where id = #{id}")
    Integer deleteBookById(Integer id);

    Integer batchDeleteByIds(List<Integer> ids);
}
